﻿using Microsoft.EntityFrameworkCore.ChangeTracking;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Fast.Extensions.DatabaseAccessor.EntityFrameworkCore
{
    /// <summary>
    /// 插入仓储接口
    /// </summary>
    public interface IInsertableRepository<TEntity> : IRootInsertableRepository<TEntity, DefaultDbContextLocator>
        where TEntity : class, IRootEntity, new()
    {

    }
    /// <summary>
    /// 插入仓储接口
    /// </summary>
    public interface IRootInsertableRepository<TEntity, TDbContextLocator> : IRootInsertableRepository<TEntity>
        where TEntity : class, IRootEntity, new()
        where TDbContextLocator : class, IDbContextLocator
    {

    }
    /// <summary>
    /// 插入仓储接口
    /// </summary>
    public interface IRootInsertableRepository<TEntity> : IRootRepositoryBase
        where TEntity : class, IRootEntity, new()
    {
        /// <summary>
        /// 新增一条记录
        /// </summary>
        /// <param name="entity">实体</param>
        void Insert(TEntity entity);
        /// <summary>
        /// 新增一条记录并返回带跟踪信息的实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>带跟踪信息的实体</returns>
        EntityEntry<TEntity> InsertWithReturnEntity(TEntity entity);
        /// <summary>
        /// 新增多条记录
        /// </summary>
        /// <param name="entities">多个实体</param>
        void Insert(IEnumerable<TEntity> entities);
        /// <summary>
        /// 新增一条记录并立即提交
        /// </summary>
        /// <param name="entity">实体</param>
        void InsertAndCommit(TEntity entity);
        /// <summary>
        /// 新增一条记录并立即提交,返回带跟踪信息的实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>数据库中返回的带跟踪信息的实体</returns>
        EntityEntry<TEntity> InsertAndCommitWithReturnEntity(TEntity entity);
        /// <summary>
        /// 新增多条记录并立即提交
        /// </summary>
        /// <param name="entities">多个实体</param>
        void InsertAndCommit(IEnumerable<TEntity> entities);
        /// <summary>
        /// 新增一条记录
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="cancellationToken">取消异步令牌</param>
        /// <returns>Task</returns>
        Task InsertAsync(TEntity entity, CancellationToken cancellationToken = default);
        /// <summary>
        /// 新增一条记录并返回带跟踪信息实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="cancellationToken">取消异步令牌</param>
        /// <returns>带跟踪信息实体</returns>
        Task<EntityEntry<TEntity>> InsertWithReturnEntityAsync(TEntity entity, CancellationToken cancellationToken = default);
        /// <summary>
        /// 新增多条记录
        /// </summary>
        /// <param name="entities">多个实体</param>
        /// <param name="cancellationToken">取消异步令牌</param>
        /// <returns></returns>
        Task InsertAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);
        /// <summary>
        /// 新增一条记录并立即提交
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="cancellationToken">取消异步令牌</param>
        Task InsertAndCommitAsync(TEntity entity, CancellationToken cancellationToken = default);
        /// <summary>
        /// 新增一条记录并立即提交,返回带跟踪信息的实体
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="cancellationToken">取消异步令牌</param>
        /// <returns>数据库中返回的带跟踪信息的实体</returns>
        Task<EntityEntry<TEntity>> InsertAndCommitWithReturnEntityAsync(TEntity entity, CancellationToken cancellationToken = default);
        /// <summary>
        /// 新增多条记录并立即提交
        /// </summary>
        /// <param name="entities">多个实体</param>
        /// <param name="cancellationToken">取消异步令牌</param>
        Task InsertAndCommitAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);
    }
}
